package email;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 这是一个方法类，用于注册时的邮箱格式验证及验证邮件的发送
 * @author bo
 *
 */
public class SendCheckEmail {
	public static boolean sendCheckEmail(String emailAddr, String validCode) {
		String reg = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
		Pattern pat = Pattern.compile(reg);
		Matcher mat = pat.matcher(emailAddr);
		if (mat.find()) {
		      MailSenderInfo mailInfo = new MailSenderInfo();      
		      mailInfo.setMailServerHost("smtp.qq.com");      
		      mailInfo.setMailServerPort("25");      
		      mailInfo.setValidate(true);      
		      mailInfo.setUserName("2659648673@qq.com");      
		      mailInfo.setPassword("njl9123");//您的邮箱密码      
		      mailInfo.setFromAddress("2659648673@qq.com");      
		      mailInfo.setToAddress(emailAddr);
		      mailInfo.setSubject("新版信息门户验证邮件");      
		      mailInfo.setContent("请点击以下链接验证您的账户：  http://localhost:8080/Info/validemail.jsp?validCode=" + validCode + "&emailAddr=" + emailAddr); 
		      SendEmail sm = new SendEmail();
		      sm.sendTextMail(mailInfo);
		      return true;
		}			
		else {
			System.out.println("邮箱格式不正确");
			return false;
		}
	}
}
